<template>
  <div id="myToast" v-html="showText" v-if="visible"></div>
</template>

<script>
export default {
  name: 'Toast',
  props: {
    text: String
  },
  data() {
    return {
      visible: false,
      showText: ''
    }
  },
  methods: {
    hide() {
      this.visible = false
    },
    show() {
      this.updateText()
      clearTimeout(this.task)
      this.task = null
      this.visible = true
      this.task = setTimeout(() => {
        this.visible = false
      }, 2000)
    },
    continueShow() {
      clearTimeout(this.task)
      this.task = null
      this.visible = true
    },
    upDateText () {
      this.showText = this.text
    }
  }
  // 显示toast
  // 隐藏toast
  // 持续显示toast
  // 更新toast里的文本
}
</script>

<style scoped>
#myToast {
  width: 80vw;
  height: 8vh;
  position: fixed;
  top: 50%;
  left: 10%;
  z-index: 999;
  border-radius: 20px;
  /* line-height: px2rem(20); */
  padding: 18px 0px;
  background: #ccc;
  font-size: px2rem(14);
  color: white;
  text-align: center;
  word-break: break-all;
  box-sizing: border-box;
}
</style>
